Skip to content

[rfw] Fix fontWeight not applied in release mode#11581

Open
iam-abhijha wants to merge 2 commits intoflutter:mainfrom
iam-abhijha:fix/rfw-font-weight-release-mode
Open

[rfw] Fix fontWeight not applied in release mode#11581
iam-abhijha wants to merge 2 commits intoflutter:mainfrom
iam-abhijha:fix/rfw-font-weight-release-mode

Conversation

@iam-abhijha
Copy link
Copy Markdown

@iam-abhijha iam-abhijha commented Apr 25, 2026

Fixes the fontWeight property of RFW TextStyle (and StrutStyle) not being applied in release mode for Text widgets.

Fixes flutter/flutter#180223

Root cause

ArgumentDecoders.textStyle (and strutStyle) decoded fontWeight using enumValue(FontWeight.values, ...), which matched the input string against FontWeight.value.toString().split('.').last. FontWeight is not a real Dart enum; it is a hand-crafted class with static const members. In AOT/release builds, toString() for such classes is not guaranteed to return the same human-readable name (tree-shaking can strip debug labels), so all matches silently fail and null is returned, causing Flutter to fall back to the default weight (w400).

Fix

Added a new ArgumentDecoders.fontWeight static method that maps strings ("w100""w900", "normal", "bold") and integers (100900) to the correct FontWeight constant using an explicit switch, without relying on toString(). Updated both textStyle and strutStyle to use this new decoder.

Pre-Review Checklist

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 25, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added the p: rfw Remote Flutter Widgets label Apr 25, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a dedicated fontWeight decoder to handle FontWeight values as strings or integers, ensuring stability in release mode. It updates strutStyle and textStyle to utilize this new decoder and includes comprehensive tests. Feedback identifies several instances where absolute keys are used for property lookups—specifically textDirection in the sweep shader, and textBaseline and overflow in textStyle—instead of relative keys, which prevents correct resolution when these structures are nested.

Comment thread packages/rfw/lib/src/flutter/argument_decoders.dart Outdated
Comment thread packages/rfw/lib/src/flutter/argument_decoders.dart Outdated
Comment thread packages/rfw/lib/src/flutter/argument_decoders.dart Outdated
@iam-abhijha iam-abhijha force-pushed the fix/rfw-font-weight-release-mode branch 2 times, most recently from d9c573b to a8bd4b5 Compare April 25, 2026 17:11
@stuartmorgan-g
Copy link
Copy Markdown
Collaborator

Thanks for the contribution!

In the future, please do not delete the checklist that is in the PR template; it is there for a reason. This PR is missing required elements described in the checklist, which need to be addressed before it moves forward with review.

I am marking the PR as a Draft. Please re-add and complete the checklist, updating the PR as appropriate, and when that’s complete please feel free to mark the PR as ready for review.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft April 28, 2026 18:22
@iam-abhijha iam-abhijha marked this pull request as ready for review April 29, 2026 05:28
@iam-abhijha
Copy link
Copy Markdown
Author

@stuartmorgan-g

Thanks for the feedback! I've re added the PR template checklist and completed all applicable items. I have marked PR as Ready for review. Also this is my first time contributing to open source, so I appreciate the guidance!

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a dedicated fontWeight decoder to resolve issues with FontWeight stability in release mode, updating TextStyle and StrutStyle to utilize it. It also fixes a key resolution bug in the sweep shader decoder and includes comprehensive unit tests for the new decoding logic. Feedback suggests simplifying the numeric FontWeight mapping by leveraging the FontWeight.values list for improved conciseness and robustness.

Comment thread packages/rfw/lib/src/flutter/argument_decoders.dart
@stuartmorgan-g stuartmorgan-g requested a review from Hixie April 29, 2026 14:14
@stuartmorgan-g
Copy link
Copy Markdown
Collaborator

It looks like you've run the autoformatter on some files that don't use it (look for the // This file is hand-formatted. comment at the start of the file), causing a lot of unrelated changes. Those should be reverted so reviewers can see what's actually changed.

@iam-abhijha iam-abhijha force-pushed the fix/rfw-font-weight-release-mode branch 2 times, most recently from 524ee17 to 1944db2 Compare April 29, 2026 14:32
@iam-abhijha
Copy link
Copy Markdown
Author

@stuartmorgan-g

Apologies for that, the auto-formatter was mistakenly run on the hand-formatted files. I've reverted all unrelated formatting changes; the PR now only touches argument_decoders.dart (new fontWeight decoder + two call site updates), argument_decoders_test.dart (regression test), CHANGELOG.md, and pubspec.yaml.

@iam-abhijha iam-abhijha force-pushed the fix/rfw-font-weight-release-mode branch from f919678 to 359bc88 Compare April 29, 2026 14:38
@stuartmorgan-g
Copy link
Copy Markdown
Collaborator

Apologies for that, the auto-formatter was mistakenly run on the hand-formatted files.

Please don't just repost AI-generated comments verbatim; reviewers don't need to have their review feedback repeated back to them.

@iam-abhijha iam-abhijha force-pushed the fix/rfw-font-weight-release-mode branch 2 times, most recently from 0f0019b to 869467b Compare April 29, 2026 14:58
FontWeight is not a real Dart enum; it is a hand-crafted class with
static const members. The previous implementation decoded fontWeight via
enumValue(), which matched strings against FontWeight.value.toString().
In AOT/release builds this is not guaranteed to be stable, so matches
silently failed and fontWeight defaulted to null (rendered as w400).

Add a dedicated ArgumentDecoders.fontWeight() method that maps strings
("w100"-"w900", "normal", "bold") and integers (100-900) to the correct
FontWeight constant using an explicit switch, without relying on
toString(). Update textStyle and strutStyle to use it.

Also fix three pre-existing bugs where absolute keys were used instead
of relative keys: textDirection in the sweep shader decoder, textBaseline
and overflow in textStyle.

Fixes flutter/flutter#180223

Made-with: Cursor
@iam-abhijha iam-abhijha force-pushed the fix/rfw-font-weight-release-mode branch from 869467b to a41ff8d Compare April 29, 2026 15:01
@iam-abhijha
Copy link
Copy Markdown
Author

Apologies for that, the auto-formatter was mistakenly run on the hand-formatted files.

Please don't just repost AI-generated comments verbatim; reviewers don't need to have their review feedback repeated back to them.

Sorry about that It's my first pr not much aware of rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: rfw Remote Flutter Widgets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFW] Text widget fontWeight not applied in release mode

2 participants